package com.example.hospital.mis.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.hospital.common.R;
import com.example.hospital.mis.controller.form.docker.AddDockerForm;
import com.example.hospital.db.pojo.DoctorEntity;
import com.example.hospital.service.DoctorService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController("MisDockerController")
@RequestMapping("mis/docker")
public class DockerController {
  @Value("${result.key}")
  private String res;
  @Resource
  private DoctorService doctorService;
  
  @GetMapping("/{id}")
  //  @SaCheckPermission(value = { "ROOT", "DOCKER:SELECT" }, mode = SaMode.OR)
  public R getDockerById(@PathVariable("id") Integer id) {
    DoctorEntity docker = doctorService.getById(id);
    return R.ok().put(res, docker);
  }
  
  @PostMapping("/addDocker")
  //  @SaCheckPermission(value = { "ROOT", "DOCKER:INSERT" }, mode = SaMode.OR)
  public R addDocker(@RequestBody @Valid AddDockerForm form) {
    DoctorEntity docker = BeanUtil.toBean(form, DoctorEntity.class);
    boolean bool = doctorService.save(docker);
    return R.ok().put("result", bool);
  }
}
